package com.hqully.labmanage.controller;

import com.hqully.labmanage.domain.entity.Student;
import com.hqully.labmanage.domain.dto.StudentDTO;
import com.hqully.labmanage.service.StudentService;
import com.hqully.labmanage.utils.ResultVOUtil;
import com.hqully.labmanage.domain.dto.PageDTO;
import com.hqully.labmanage.domain.vo.ResultVO;

import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 学生数据接口
 * <p>
 *
 * @author hqully
 * @version 1.0
 * @date 2022-10-08 11:17:19
 */
@Api(tags = {"学生数据接口"})
@Slf4j
@RestController
@RequestMapping("/api/student")
public class StudentController extends BaseController {

    @Resource
    private StudentService studentService;

    @ApiOperation(value = "分页条件查询学生列表")
    @GetMapping("/page-students")
    public ResultVO<PageInfo<StudentDTO>> pageStudents(PageDTO page, StudentDTO studentDTO) {
        PageInfo<StudentDTO> studentPage = studentService.pageStudents(page, studentDTO);
        return ResultVOUtil.success(studentPage);
    }

    @ApiOperation(value = "条件查询学生列表")
    @GetMapping("/list-students")
    public ResultVO<List<StudentDTO>> listStudents(StudentDTO studentDTO) {
        List<StudentDTO> studentList = studentService.listStudents(studentDTO);
        return ResultVOUtil.success(studentList);
    }

    @ApiOperation(value = "添加学生")
    @PostMapping("/add-student")
    public ResultVO<StudentDTO> addStudent(@Validated @RequestBody StudentDTO studentDTO) {
        studentService.addStudent(studentDTO);
        return ResultVOUtil.success("添加学生成功");
    }

    @ApiOperation(value = "更新学生")
    @PostMapping("/update-student")
    public ResultVO<StudentDTO> updateStudent(@Validated @RequestBody StudentDTO studentDTO) {
        studentService.updateStudent(studentDTO);
        return ResultVOUtil.success("更新学生成功");
    }

    @ApiOperation(value = "删除学生")
    @DeleteMapping("/delete-student/{id}")
    public ResultVO<StudentDTO> deleteStudent(@PathVariable("id") Integer id) {
        studentService.deleteStudentById(id);
        return ResultVOUtil.success("删除学生成功");
    }

}

